/*
*	Burndown:
*
*	@ totalTasks - total ammount of the project's task
*	@ tasksDone - ammount of tasks finished.
*	@ tasksToday - ammount of tasks finished today.
*	@ daysGone - days since the project started.
*	@ daysToGo - days until the project's final date.
*	@ totalProgress - percentage of projects accomplish
*
*/

/**
*	Class: Burndown
*
*	Generates information about the project's burndown.
*
*	@param project - the project that will have the burndown plotted
*/
function Burndown(project){

	var today = new Date();
	var startDate = project.startDate;
	var finalDate = project.getFinalizationDate();
	
	this.projectLate;
	if(today.getTime() > startDate.getTime()) //TODO check this condition
		this.projectLate = true;
	else
		this.projectLate = false;
		
	this.daysGone = PostIt.prototype.diffDays(today, startDate);
	this.daysToGo = PostIt.prototype.diffDays(finalDate, today);
        this.projectTime = PostIt.prototype.diffDays(finalDate, startDate);
	
	this.totalTasks = project.todo.getPostsAmmount();
	this.totalTasks += project.doing.getPostsAmmount();
	this.totalTasks += project.impeded.getPostsAmmount();
	this.totalTasks += project.done.getPostsAmmount();
	
	this.tasksDone = project.done.getPostsAmmount();
	
	var done = project.done.getPosts();
        var postCmp = new PostIt();
	this.tasksToday = 0;
	for(var i in done){
            if (typeof done[i] == typeof postCmp) {
		if(done[i].daysFinalized() == 0){
			this.tasksToday += 1;
                }
            }
	}
        
	
        if(this.totalTasks <= 0){
            this.progress = 0;
        } else {
            this.progress = Math.floor( 100 * parseFloat(this.tasksDone) / parseFloat(this.totalTasks));
        }
        
        //this.status = (tasksDone / daysGone) / (totalTasks / projectTime);  
	
	
}

